package com.dongline.te
import javafx.application.Application
import javafx.stage.Stage
import org.apache.spark.{SparkConf, SparkContext}

class BroadcastDriver extends Application {

/*
广播变量的使用，将变量发送到所有executor中。便于计算
 */
  override def start(primaryStage: Stage): Unit = {
    val conf =new SparkConf().setMaster("local").setAppName("1")
    //设置spark的内存
    conf.set("spark.testing.memory", "471859200")
    val sc =new SparkContext(conf)
    val rdd1 =sc.textFile("D:/broadcast.txt").map(_.split(","))
    //发送广播变量，广播变量会发送到每一个executor上
    val rdd3=sc.broadcast(Array(1,2,3))
    //使用value引用广播变量
    val  rdd4 = rdd1.map(x => x(0).toInt+rdd3.value.apply(1))
    print(rdd4.collect.toBuffer)
  }
}
